package response

import (
	"reflect"
)

type DataResponse struct {
	Err  int
	Data interface{}
	Msg  string
}

func Reponse(errCode int, data interface{}, msg string) DataResponse {

	if data == nil {
		data = ""
	} else {
		if reflect.ValueOf(data).IsNil() {
			data = ""
		}
		if reflect.TypeOf(data).String() == "[]interface {}" {
			if reflect.ValueOf(data).Len() == 0 {
				data = ""
			}
		}
		if reflect.TypeOf(data).String() == "[]orm.Params" {
			if reflect.ValueOf(data).Len() == 0 {
				data = ""
			}
		}
	}

	resp := DataResponse{
		Err:  errCode,
		Data: data,
		Msg:  msg,
	}
	return resp
}

